package com.talent.service.iot.mqtt.model.response;

import com.talent.service.iot.mqtt.model.fix.TlMqttFixedHead;
import com.talent.service.iot.mqtt.model.variable.TlMqttConnackVariableHead;
import io.netty.handler.codec.mqtt.MqttConnectReturnCode;
import io.netty.handler.codec.mqtt.MqttMessageType;

/**
 * @ClassName：TlMqttConnackRes
 * @Author: hszhou
 * @Date: 2024/11/25 11:12
 * @Description: 连接请求的响应
 */
public class TlMqttConnack  {

    private TlMqttFixedHead fixedHead;
    private TlMqttConnackVariableHead variableHead;

    public TlMqttFixedHead getFixedHead() {
        return fixedHead;
    }

    public void setFixedHead(TlMqttFixedHead fixedHead) {
        this.fixedHead = fixedHead;
    }

    public TlMqttConnackVariableHead getVariableHead() {
        return variableHead;
    }

    public void setVariableHead(TlMqttConnackVariableHead variableHead) {
        this.variableHead = variableHead;
    }



    public static TlMqttConnack of(int currentSession, MqttConnectReturnCode returnCode){
        TlMqttConnack res = new TlMqttConnack();
        TlMqttFixedHead fixedHead= TlMqttFixedHead.of(MqttMessageType.CONNACK);
        res.setFixedHead(fixedHead);
        TlMqttConnackVariableHead variableHead =TlMqttConnackVariableHead.of(currentSession,returnCode);
        res.setVariableHead(variableHead);
        return res;
    }
    @Override
    public String toString() {
        return "TlMqttConnack{" +
                "fixedHead=" + fixedHead +
                ", variableHead=" + variableHead +
                '}';
    }
}
